package main

import (
	// "fmt"
	"fmt"
	"learn-opengl/camera"
	myglfw "learn-opengl/glfw"
	inputparam "learn-opengl/inputParam"
	"learn-opengl/light"
	"learn-opengl/object/block"
	"learn-opengl/object/item"
	"learn-opengl/opengl/shader"
	"learn-opengl/opengl/texture"
	"learn-opengl/player"
	"learn-opengl/scene"
	. "learn-opengl/util"
	"runtime"

	"github.com/go-gl/gl/v3.3-core/gl"
	"github.com/go-gl/glfw/v3.2/glfw"
	"github.com/go-gl/mathgl/mgl32"
)

var input = inputparam.Inputparam{}

func main() {
	runtime.LockOSThread()
	win := myglfw.InitGl(&input,800,600)
	defer glfw.Terminate()

	shader,err := shader.InitShader("./src/shaders/Basic.glsl")
	Herr(err)
	shader.Bind()

	err = item.LoadTextureDesc()
	Herr(err)

	tex := texture.NewTexture("texture.png")
	tex.Bind(1)
	
	block.Build()



	shader.SetUniform1i("diffuse",1)
	camera := camera.NewCamera(mgl32.Vec3{0,10,0})
	scne := scene.NewScene(shader,camera)
	player := player.NewPlayer(camera,scne)

	// win.SetInputMode(glfw.CursorMode, glfw.CursorNormal)
	for !win.ShouldClose() {
		glfw.PollEvents()
		gl.ClearColor(0.57, 0.71, 0.77, 1)
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		camera.SetUni(shader)

		light.SetUpDirLight(shader)
		// showFps()
		scne.Update()
		player.Update(&input)


		for i:=1;i<64;i++ {
			block.Blocks[i].Draw(shader,mgl32.Vec3{float32(i),20,0})
		}
		win.SwapBuffers()
	}
}

func update() {

}

var pre = 0.0
func showFps() {
	dura := glfw.GetTime() - pre
	fmt.Println("fps: " , 1/dura)
	pre = glfw.GetTime()
}